﻿using Microsoft.Xna.Framework;
using System;

namespace Library
{
    public class Component
    {
        public Screen Parent;
        public bool Initialized = false;
        public bool Visible = true;

        int drawOrder = 1;
        public event ComponentDrawOrderChangedEventHandler DrawOrderChanged;

        public int DrawOrder 
        {
            get { return drawOrder; }
            set 
            {
                int last = drawOrder;
                drawOrder = value;
                if (DrawOrderChanged != null)
                    DrawOrderChanged(this, new ComponentDrawOrderChangedEventArgs(this, last, this.Parent.Components));
            }
        }
        public Component(Screen Parent)
        {
            InitializeComponent(Parent);
        }

        public Component()
        {
            InitializeComponent(Engine.DefScreen);
        }

        protected virtual void InitializeComponent(Screen Parent)
        {
            Parent.Components.Add(this);
            Initialized = true;
        }

        public virtual void Update()
        { 
        
        }

        public virtual void Draw()
        { 
        
        }

        public virtual void DisableComponent()
        {
            Parent.Components.Remove(this);
        }
    }

    public class ComponentDrawOrderChangedEventArgs : EventArgs
    {
        public Component Component;
        public int lastDrawOrder;
        public CompCollection ParentCollection;
        public ComponentDrawOrderChangedEventArgs(Component Component, int lastDrawOrder, CompCollection ParentCollection)
        {
            this.Component = Component;
            this.lastDrawOrder = lastDrawOrder;
            this.ParentCollection = ParentCollection;
        }
    }

    public delegate void ComponentDrawOrderChangedEventHandler(
    object sender, ComponentDrawOrderChangedEventArgs e);
}